package com.javatiaocao.myblog.controller;

import com.javatiaocao.myblog.constant.CodeType;
import com.javatiaocao.myblog.model.User;
import com.javatiaocao.myblog.model.UserDTO;
import com.javatiaocao.myblog.service.UserService;
import com.javatiaocao.myblog.utils.DataMap;
import com.javatiaocao.myblog.utils.JsonResult;
import com.javatiaocao.myblog.utils.MD5Util;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
public class RegisterController {

    @Autowired
    private UserService userService;




    @PostMapping(value = "/register")
    public String register(User user, HttpServletRequest request){//userdto接收前端的企业规范
        try{

            //注册
            DataMap data = userService.register(user);
            return JsonResult.build(data).toJSON();


        }catch (Exception e){
            log.error("RegisterController exeception",user,e);
        }

        return JsonResult.fail(CodeType.SERVER_EXCEPTION).toJSON();

    }

}
